<?php

namespace App\Http\Middleware;

use App\Models\Freelancer;
use Closure;
use Illuminate\Http\Request;

class FreelancerVerified
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse)  $next
     * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
     */
    public function handle(Request $request, Closure $next)
    {
        $freelancer = $request->user();

        // 检查是否已通过身份验证
        if ($freelancer->verification_status !== Freelancer::VERIFICATION_APPROVED) {
            return response()->json([
                'success' => false,
                'message' => '请先完成身份验证',
                'data' => [
                    'verification_status' => $freelancer->verification_status,
                    'verification_note' => $freelancer->verification_note
                ]
            ], 403);
        }

        return $next($request);
    }
}
